package logic

import (
	"context"
	"zg4_month_exam/user/rpc/userclient"

	"zg4_month_exam/user/api/internal/svc"
	"zg4_month_exam/user/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddLogic) Add(req *types.Addrequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	conn, err := l.svcCtx.UserRpc.Add(context.Background(), &userclient.AddRequest{
		Index:    req.Index,
		Choose:   int64(req.Choose),
		Analyzer: req.Analyzer,
		Types:    req.Types,
		Name:     req.Name,
		Id:       int64(req.Id),
	})
	if err != nil {
		return &types.Response{
			Code: int(conn.Code),
			Msg:  conn.Msg,
			Data: nil,
		}, nil
	}
	return &types.Response{
		Code: int(conn.Code),
		Msg:  conn.Msg,
		Data: conn.Data,
	}, nil
}
